package com.hxd.otc.module.convenience.fragment;

import android.app.Activity;
import android.content.Intent;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseRecyclerFragment;
import com.hxd.otc.module.convenience.adapter.PaymentMethodAdapter;
import com.hxd.otc.module.convenience.bean.PaymentMethodBean;
import com.hxd.otc.module.convenience.contract.PaymentMethodContract;
import com.hxd.otc.module.convenience.presenter.PaymentMethodPresenter;
import com.hxd.otc.utils.UIUtils;

import butterknife.OnClick;

/**
 * Created by lzy on 2018/12/12 0012.
 * description ${支付对话框-支付方式}
 */
public class PaymentMethodFragment extends BaseRecyclerFragment<PaymentMethodPresenter, PaymentMethodAdapter, PaymentMethodBean> implements PaymentMethodContract.IView {

    public static final String RESULT_EXTRA_PAYMENT_METHOD = "result_payment_method";

    @Override
    protected PaymentMethodAdapter createAdapter() {
        return new PaymentMethodAdapter(getContext());
    }

    @Override
    protected PaymentMethodPresenter createPresenter() {
        return new PaymentMethodPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_payment_method;
    }

    @Override
    protected void initData() {
        super.initData();
        mPresenter.loadData(true);
    }

    @Override
    public void onItemClick(int position) {
        if (getTargetFragment() != null) {
            Intent intent = new Intent();
            intent.putExtra(RESULT_EXTRA_PAYMENT_METHOD, mAdapter.getItem(position));
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, intent);
        }
        getFragmentManager().popBackStack();
    }

    @Override
    public boolean isEnableLoadMore() {
        return false;
    }

    @OnClick(R.id.iv_close)
    public void onClick() {
        UIUtils.dismissDialogFragment(((PayDialogFragment) getParentFragment()));
    }

}
